package com.sl.springboot.swagger.controller;

import com.sl.springboot.swagger.bean.User;
import com.sl.springboot.swagger.service.UserService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.List;

@Controller
@EnableSwagger2
public class IndexController {

    @Autowired
    private UserService userService;

    //访问：http://localhost:8081/swagger-ui.html#/index-controller
    @ApiOperation(value = "获取用户列表", notes = "获取用户列表", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
    //@ApiImplicitParam(name = "user", value = "用户详细实体user", required = true, dataType = "User")
    @RequestMapping(value = "findAll", method=RequestMethod.GET)
    @ResponseBody
    public List<User> findAll(){
       return userService.findAll();
    }

    @ApiOperation(value = "根据名字查询用户", notes = "根据名字查询用户", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
   // @ApiImplicitParam(name = "userName", value = "user name", required = true, dataType = "String")
    @RequestMapping(value = "findUserByName", method=RequestMethod.GET)
    @ResponseBody
    public User findUserByName(@ApiParam(value="userName", required=true) @RequestParam(value = "userName", required = false) String userName){
        return userService.findUserByName(userName);
    }
}
